package com.zr.task.presenter;

import android.content.Context;

import com.zh.baselibrary.base.BasePresenter;
import com.zh.baselibrary.model.TaskModel;
import com.zh.baselibrary.netutils.BaseResp;
import com.zh.baselibrary.rxjava.RxSubscribe;
import com.zh.baselibrary.utils.JsonUtils;
import com.zh.baselibrary.utils.LogUtils;
import com.zh.baselibrary.utils.TTSUtils;
import com.zh.model.task.home.ValidateBean;
import com.zh.model.task.home.ValidateResBean;
import com.zh.model.task.relation.AssociateTag;
import com.zr.task.R;
import com.zr.task.presenter.view.RelationView;

import java.util.List;

import io.reactivex.Observable;

public class RelationPresenter extends BasePresenter<RelationView> {
    private TaskModel model;

    @Override
    public void attachModel(Context context) {
        model  = new TaskModel(context);
    }
    public void identifyCode(ValidateResBean mBean) {
        LogUtils.e(JsonUtils.objectToString(mBean));
        Observable<BaseResp<ValidateBean>> observable = getObservable(model.identifyCode(mBean));
        observable.subscribe(new RxSubscribe<BaseResp<ValidateBean>>() {
            @Override
            public void onSuccess(BaseResp<ValidateBean> validateBeanBaseResp) throws Exception {
                getView().rediaCodeValidateSuccess(validateBeanBaseResp.getData());
            }

            @Override
            public void onHint(String hint) {
               getView().onHint(hint);
            }
        });
    }
    public void associate(String schoolId, List<AssociateTag> associateTagList) {
        LogUtils.e(JsonUtils.objectToString(associateTagList));
        Observable<BaseResp<Object>> observable = getObservable(model.associateCurrencyTag(schoolId,associateTagList));
        observable.subscribe(new RxSubscribe<BaseResp<Object>>() {
            @Override
            public void onSuccess(BaseResp<Object> objectBaseResp) throws Exception {
                String tip = getContext().getString(R.string.relate_success)+associateTagList.size()+getContext().getString(R.string.unit);
                TTSUtils.getInstance().speak(tip);
                getView().associateSuccess();
            }

            @Override
            public void onHint(String hint) {
                getView().onHint(hint);
            }
        });
    }
}
